package response

import (
	"net/http"

	"gitee.com/shiwjlinux/arm/exception"
	"github.com/gin-gonic/gin"
)

func Success(ctx *gin.Context, data interface{}) {
	ctx.JSON(http.StatusOK, data)
}

func Failed(ctx *gin.Context, err error) {
	httpStatus := http.StatusInternalServerError

	if v, ok := err.(*exception.ApiException); ok {
		if v.HttpCode != 0 {
			httpStatus = v.HttpCode
		}
	} else {
		err = exception.ErrServerInternal(err.Error())
	}

	ctx.JSON(httpStatus, err)
	ctx.Abort()
}
